home *** CD-ROM | disk | FTP | other *** search
/ The Arsenal Files 8 / The Arsenal Files Collection #8 (Arsenal Computer) (1996).ISO / prg_gen / euphor14.zip / SIEVE.EX < prev    next >
Text File  |  1996-01-19  |  1KB  |  61 lines

  1.            ---------------------------
  2.            -- Prime Sieve Benchmark --
  3.            ---------------------------
  4.  
  5. without type_check -- makes no difference
  6.  
  7. constant BATCH = 50
  8. constant BENCH_TIME = 15
  9.  
  10. constant SIZE = 500  -- finds primes up to SIZE*2+1
  11.              -- (only tests odd numbers)
  12. constant ON = 1, OFF = 0
  13. constant SCREEN = 1
  14.  
  15. sequence flags 
  16.  
  17. function sieve()
  18.     integer prime, start, count, still_prime
  19.  
  20.     count = 0
  21.     flags = repeat(ON, SIZE)
  22.     for i = 1 to SIZE do
  23.     still_prime = flags[i]
  24.     if still_prime then
  25.         prime = i + i
  26.         prime = prime + 1 
  27.         start = prime + i
  28.         for k = start to SIZE by prime do
  29.         flags[k] = OFF
  30.         end for 
  31.         count = count + 1
  32.     end if
  33.     end for
  34.     return count
  35. end function
  36.  
  37. atom t, cycles
  38.  
  39. puts(SCREEN, "prime sieve benchmark ...\n")
  40. cycles = 0
  41. t = time()
  42. while time() < t + BENCH_TIME do
  43.     for iter = 1 to BATCH do
  44.     if sieve() != 167 then
  45.         puts(SCREEN, "whoops!\n")
  46.     end if
  47.     end for
  48.     cycles = cycles + BATCH
  49. end while
  50. t = time() - t
  51. printf(SCREEN, "%6.1f sieves per second\n", cycles / t)
  52.  
  53. -- display results
  54. puts(SCREEN, "   2") -- 2 is also a prime
  55. for i = 1 to SIZE do
  56.     if flags[i] then
  57.     printf(SCREEN, " %3d", i*2+1)
  58.     end if
  59. end for
  60.  
  61.